#!/bin/sh

### BEGIN INIT INFO
# Provides:        gpio_halt
# Required-Start:  $network $syslog
# Required-Stop:   $network $syslog
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description:
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

. /lib/lsb/init-functions

DAEMON="/usr/bin/gpio_start_cmd"
DAEMON_OPT="-i 4 -o 17 -c /etc/gpio_start_cmd.ksh -d 5"

PIDFILE=/var/run/gpio_halt.pid
test -x $DAEMON || exit 5

RUNASUSER=root
UGID=$(getent passwd $RUNASUSER | cut -f 3,4 -d:) || true

case $1 in
        start)
                log_daemon_msg "Starting" "gpio_halt"
                start-stop-daemon --make-pidfile --background --start --pidfile $PIDFILE --startas $DAEMON -- $DAEMON_OPT
                status=$?
                log_end_msg $status
                ;;
        stop)
                log_daemon_msg "Stopping" "gpio_halt"
                start-stop-daemon --stop --signal 3 --quiet --pidfile $PIDFILE
                log_end_msg $?
                rm -f $PIDFILE
                ;;
        restart|force-reload)
                $0 stop && sleep 2 && $0 start
                ;;
        try-restart)
                if $0 status >/dev/null; then
                        $0 restart
                else
                        exit 0
                fi
                ;;
        reload)
                exit 3
                ;;
        status)
                status_of_proc $DAEMON "gpio_halt"
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
                exit 2
                ;;
esac

